<template>
  <div class="user-like">
  	<!-- 头部 -->

    <div class="like-top fs-xl py-3" style="text-align: center; background-color: #eee">
        <div class="top-name text-grey">------- <i class="iconfont icon-xinaixin"></i>{{title}} -------</div>
    </div>
    <!-- 商品 -->
    <div class="product d-flex pt-2 flex-wrap jc-between">
    	
    		<div @click="$router.push('/productDetail/'+item.id)" v-for="(item,i) in userLikeList" :key="i" class="product_item mx-1  my-2 bg-white">
    			<van-image
    			style="width: 100%; height: 200px"
    			:src="item.image"
          >
    		</van-image>
    		<div>
    			<div style="text-align: center; text-decoration: blink">
    				<div style="height: 30px;">
    					<span class="flex-1 fs-xl">{{item.name}}</span>
    				</div>
    				<div class="d-flex jc-between py-2">
    					<div class="pl-3 text-pink">￥
    					<span class="text-pink fs-lg fs-xxxl">{{item.price/100}}</span>
    				</div>
    				<div class="pr-3">
    					<span style="text-decoration: line-through">￥{{item.price/100}}</span>
    				</div>
    				</div>
    			</div>
    		</div>
    	</div>
    </div>

    <!-- 加载更多 -->
    <div></div>

  </div>
</template>

<script>
export default {
  props: ["title"],
  data() {
    return {
        url: '',
        userLikeList: [],
        noData:true //判断是否数据全部加载完成 true为全部加载完

 

    };
  },
  components: {
    },
  methods: {
      async getUserLike(){
          let searchKey = this.$store.getters.search_history
          if (searchKey.length>0) {
            searchKey.forEach(async (item,i) => {
                const res = await this.$http.get(`search.do?page=${1}&size=${10000}&keyword=${item}`)
                res.data.rows.forEach((item2,i2) => {
                  this.userLikeList.push(item2)
                })
              
                if (this.userLikeList.length === 0) {
                  console.log(this.userLikeList.length)
                  const res = await this.$http.get(`search.do?page=${1}&size=${10000}`)
                  this.userLikeList = res.data.rows
                }
          })
            
          }else {
            const res = await this.$http.get(`search.do?page=${1}&size=${10000}`)
            this.userLikeList = res.data.rows
          }     
      },
        // 加载开始 vuescroll
        loadStart(done){
          setTimeout(()=>{
                // 这里写 ajax 业务请求，在数据请求到后执行 done() 关闭动画
                done() 
              },1600)
        }


  },
  created() {
     this.getUserLike()
  }
};
</script>

<style lang="scss" scoped>
  .product_item {
  	width: 47.5%;
  }
</style>


